﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class scenes2Ui : MonoBehaviour
{
    public static scenes2Ui ui;
    private void Awake()
    {
        ui = this;
    }
    [Header("失败界面")]
    public GameObject GameOverPanel;
    public void ShowGameOverPanel()
    {
        GameOverPanel.gameObject.SetActive(true);
        Time.timeScale = 0;
    }

    [Header("设置界面")]
    public GameObject SystemPanel;
    public void ShowSystemPanel()
    {
        SystemPanel.gameObject.SetActive(true);
        Time.timeScale = 0;
    }
    public void BackGame()
    {
        SystemPanel.gameObject.SetActive(false);
        Time.timeScale = 1;
    }
    public void BackScene1()
    {
        SceneManager.LoadScene(1);
        Time.timeScale = 1;
    }
    public void BackMap()
    {
        SceneManager.LoadScene(2);
        Time.timeScale = 1;
    }

    [Header("帮助界面")]
    public GameObject HelpPanel;
    public void ShowHelpPanel()
    {
        HelpPanel.gameObject.SetActive(true);
    }
    public void HideHelpPanel()
    {
        HelpPanel.gameObject.SetActive(false);
    }


    [Header("金币数量")]
    public Text coinText;
    public void SetCoin(int value)
    {
        coinText.text = value.ToString();
    }

    [Header("音量按钮图集")]
    public Sprite Mysprit;
    [Header("默认的图集")]
    private Sprite Defallsprit;
    [Header("音量按钮")]
    public Button source;
    public int sourceValue = 1;
    public void SetSourceButton()
    {
        sourceValue = -sourceValue;
        if (sourceValue==-1)
        {
            source.image.sprite = Mysprit;
        }
        else if (sourceValue==1)
        {
            source.image.sprite = Defallsprit;
        }
    }

    public GameObject EnemyBloodPanel;

    [Header("胜利界面")]
    public GameObject WinPanel;
    public void ShowWinPanel()
    {
        WinPanel.SetActive(true);
    }

    [Header("加点界面")]
    public GameObject ShopPanel;
    public Text attackValue;
    public GameObject Coinbugou;
    public void ShowShopPanel()
    {
        ShopPanel.gameObject.SetActive(true);
    }
    public void HideShopPanel()
    {
        ShopPanel.gameObject.SetActive(false);
    }
    public void AddAttack()
    {
        if (int.Parse(coinText.text)>= 20)
        {
            Player.con.attack++;
            GameController.con.coin -= 20;
        }
        else if (GameController.con.coin < 20)
        {
            Coinbugou.SetActive(true);
            Invoke("HideNullCoin", 1f);
        }
        
    }
    public void HideNullCoin()
    {
        Coinbugou.SetActive(false);
    }
    // Use this for initialization
    void Start()
    {
        coinText.text = KeepCoin.con.CoinAll.ToString();
        attackValue.text = KeepCoin.con.AttackValue.ToString();
        Defallsprit = source.image.sprite;
    }

    // Update is called once per frame
    void Update()
    {
        SavaData();
        coinText.text = GameController.con.coin.ToString();
        attackValue.text = Player.con.attack.ToString();
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            ShowSystemPanel();
        }
    }

    public void SavaData()
    {
        KeepCoin.con.CoinAll = int.Parse( coinText.text);
    }
}
